import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'NativeUtil/NativeUtil.dart';
import 'store/Store.dart';
import 'core/Routers.dart';

class App extends StatelessWidget {

  const App({Key? key}) : super(key: key);

  //全局的navigatorKey
  static final GlobalKey<NavigatorState> navigatorKey = GlobalKey(debugLabel: 'navigate');
  //
  static String? cookie;
  @override
  Widget build(BuildContext context) {
    //设置全局状态 上下文
    Store.setContext(context);

    //获取浏览器参数
    //http://localhost:52143/#/loginPage?name=100

    //获取浏览器地址的"#" 后面的字符串
    var defaultRoute = window.defaultRouteName;
    Uri route = Uri.parse(defaultRoute);
    debugPrint(defaultRoute); // /loginPage?name=100
    //获取route "?" 前面的字符串
    // debugPrint(route.path); // /loginPage
    //获取route "?" 后面的字符串

    cookie = route.queryParameters["cookie"];
    if(cookie != null) {
      //将cookie保存进网页的Cookies中
      addCookie("token_pass=" + cookie!);
      debugPrint(cookie);
    }



    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      navigatorKey: navigatorKey,
      //路由器
      onGenerateRoute: Routers.onGenerateRoute,
      initialRoute: RouteName.initPage,
    );
  }
}